<template>
  <Portlet title="服务商">
    <table class="order-table">
      <tr>
        <td align="center" style="padding-left: 5px; width: 180px">
          <img :src="'/api/ms-mongodb/file/download?fileId=' + fhbOrderBiddingLog.businessImg" style="width: 150px; height: 150px;"/>
        </td>
        <td style="min-width: 460px">
          <div class="marginBottom8">
            {{fhbOrderBiddingLog.name}}
            <el-tooltip v-if="fhbOrderBiddingLog.isAuthention == 1" class="item" effect="dark" content="已通过实名认证" placement="top-start">
              <img style="no-repeat: center; height: 16px; width: 20px" src="/static/images/faHuoBao/certification.png" alt="实名认证" title="已通过实名认证" />
            </el-tooltip>
            <el-tooltip v-if="fhbOrderBiddingLog.isAuthention !== 1" class="item" effect="dark" content="未实名认证" placement="top-start">
              <img style="no-repeat: center; height: 16px; width: 20px" src="/static/images/faHuoBao/Unproven.png" alt="未实名认证" title="未实名认证"/>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" :content="carContent" placement="top-start" style="margin-top: 5px">
              <img style="no-repeat: center; height: 14px; width: 20px" src="/static/images/faHuoBao/car.png" alt="车辆" :title="carContent" />
            </el-tooltip>
            <el-tooltip class="item" effect="dark" :content="areaContent" placement="top-start">
              <img style="no-repeat: center; height: 16px; width: 20px" src="/static/images/faHuoBao/warehouse.png" alt="仓库" :title="areaContent" />
            </el-tooltip>
          </div>
          <div class="marginBottom8">
            <span class="shiFuAddress">{{fhbOrderBiddingLog.nature}}</span><span v-if="fhbOrderBiddingLog.address"> | {{fhbOrderBiddingLog.address}} </span>
          </div>
          <div class="marginBottom8">
            <el-tooltip v-if="fhbOrderBiddingLog.favorTMJD == 1" class="item" effect="dark" content="支持汪师傅核销" placement="right">
              <img style="no-repeat: center; height: 22px; width: 46px" src="/static/images/faHuoBao/wangshifu.png" alt="汪师傅" title="支持汪师傅核销" />
            </el-tooltip>
            <el-tooltip v-if="fhbOrderBiddingLog.favorTMJD == 1" class="item" effect="dark" content="支持喵师傅核销" placement="right">
              <img style="no-repeat: center; height: 22px; width: 46px" src="/static/images/faHuoBao/miaoshifu.png" alt="喵师傅" title="支持喵师傅核销" />
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="服务承诺" placement="right">
              <img style="no-repeat: center; height: 22px; width: 61px" src="/static/images/faHuoBao/ServiceCommitment.png" alt="服务承诺" title="服务承诺"  @click="pledge($event, fhbOrder)"/>
            </el-tooltip>
          </div>
          <div class="marginBottom8">
            <span class="serviceCodeStyle">服务确认码：{{fhbOrder.serviceCode}}</span>
          </div>
          <div class="marginBottom8">
            <span>好评率：{{fhbOrderBiddingLog.evalueGoods}}%</span><span style="margin-left: 20px;">总单数：{{fhbOrderBiddingLog.orderSucessCount}}</span><span style="margin-left: 20px;">投诉数：{{fhbOrderBiddingLog.complaintCount}}</span>
          </div>
        </td>
        <td align="center">
          <div class="cell-center">
            <span class="actual-money-s">实付：</span><span style="font-size: 36px;" class="font-red">￥{{money}}</span><br>
            <span v-if="fhbOrderBiddingLog.memo">留言：<truncate :value="fhbOrderBiddingLog.memo" :maxLength="12"></truncate></span><br>
            <span>中标时间：{{fhbOrderBiddingLog.biddingDate|unixTimestampFilter}}</span>
          </div>
        </td>
        <td align="center" style="min-width: 240px;">
          <div class="cell-center">
            <slot name="tools"></slot>
          </div>
        </td>
      </tr>
    </table>
    <modal-fees-detail ref="modalFeesDetail" :orderId="orderId"></modal-fees-detail>
  </Portlet>
</template>

<script>
import {dotData} from '@/utils'
import modalFeesDetail from '@/views/fhb/myOrders/components/modal/modalFeesDetail'
export default {
  name: 'service-header',
  props: {
    orderDetail: {
      type: Object,
      required: true
    }
  },
  components: {
    modalFeesDetail
  },
  data() {
    return {
      isFhbAdminPath: -1
    }
  },
  computed: {
    // 再次下单需要提交的 单号id
    fhbOrderId() {
      return dotData(this.orderDetail, 'fhbOrder.id') || ''
    },
    fhbOrderBiddingLog() {
      return dotData(this.orderDetail, 'fhbOrderBiddingLog') || {}
    },
    fhbOrder() {
      let fhbOrder = {}
      fhbOrder = dotData(this.orderDetail, 'fhbOrder') || {}
      fhbOrder.endFee = this.orderDetail.money
      return fhbOrder
    },
    money() {
      return dotData(this.orderDetail, 'money') || 0
    },
    orderState() {
      let orderState = dotData(this.orderDetail, 'fhbOrder.orderStatus')
      // 退款单
      // let refundStatus = dotData(this.orderDetail, 'fhbOrder.refundStatus')
      // 异常单
      // let abnormalType = dotData(this.orderDetail, 'fhbOrder.abnormalType')
      // 服务中：出库、到件、出发、提货、上门,待确认：finished|750
      let orderStateArr = ['service|200', 'service|550', 'service|570', 'service|600', 'service|700', 'finished|750']
      if (orderStateArr.indexOf(orderState) >= 0 && this.isFhbAdminPath < 0) {
        return true
      } else {
        return false
      }
    },
    // 一键催单
    isShowUrge() {
      let orderState = dotData(this.orderDetail, 'fhbOrder.orderStatus')
      let orderStateArr = ['service|01', 'service|550', 'service|570', 'service|600', 'service|700']
      return orderStateArr.indexOf(orderState) >= 0
    },
    // 展示是否去聊天
    isShowToChat() {
      let orderState = dotData(this.orderDetail, 'fhbOrder.orderStatus')
      let orderStateArr = ['service|200', 'service|550', 'service|570', 'service|600', 'service|700', 'finished|750', 'evaluate|800', 'close|0', 'service|01']
      return orderStateArr.indexOf(orderState) >= 0 && this.isFhbAdminPath < 0
    },
    isShowfeesDetail() { // 除了报价中与代付款都显示
      let orderState = dotData(this.orderDetail, 'fhbOrder.orderStatus')
      // 报价中：report|100,待付款：stayPay|100
      let orderStateArr = ['report|100', 'stayPay|100']
      if (orderStateArr.indexOf(orderState) < 0) {
        return true
      } else {
        return false
      }
    },
    isShowPayment() {
      let orderState = dotData(this.orderDetail, 'fhbOrder.orderStatus')
      // 报价中：report|100,待付款：stayPay|100
      let orderStateArr = ['report|100', 'stayPay|100']
      if (orderStateArr.indexOf(orderState) < 0) {
        return false
      } else {
        return true
      }
    },
    showComplaint() {
      let orderState = dotData(this.orderDetail, 'fhbOrder.orderStatus')
      // 已完成：evaluate|800,已关闭：close|0
      let orderStateArr = ['evaluate|800', 'close|0']
      if (orderStateArr.indexOf(orderState) < 0 || this.isFhbAdminPath > 0) { // 只在发货宝操作
        return false
      } else {
        return true
      }
    },
    carContent() {
      if (this.fhbOrderBiddingLog.carsHold) {
        return '配送车辆：' + this.fhbOrderBiddingLog.cars + '辆'
      } else {
        return '配送车辆：0辆'
      }
    },
    areaNum() {
      return dotData(this.fhbOrderBiddingLog, 'area') || 0
    },
    areaContent() {
      return '仓库：' + this.areaNum + '㎡'
    },
    complainTime() {
      return parseInt((this.orderDetail.evalueForComplainTime || this.orderDetail.closeForComplainTime) / 1000) || 0
    },
    canComplaint() {
      return !!this.complainTime
    },
    orderId() {
      return dotData(this.orderDetail, 'fhbOrder.id') || ''
    },
    orderNo() {
      return dotData(this.orderDetail, 'fhbOrder.orderNo') || ''
    },
    refundIsOrNot() {
      return dotData(this.orderDetail, 'fhbOrder.orderIsCancel') || ''
    },
    // 师傅的UserId
    peopleUserId() {
      return dotData(this.orderDetail, 'fhbOrderBiddingLog.peopleUserId')
    },
    // 是否在 发货宝，且状态为：已关闭--> 才操作 再次下单
    isCloseState() {
      let orderState = dotData(this.orderDetail, 'fhbOrder.orderStatus')
      // 已完成：evaluate|800,已关闭：close|0
      if (orderState === 'close|0' && (this.isFhbAdminPath < 0)) { // 只在发货宝操作
        return true
      } else {
        return false
      }
    },
    // 是否是：退款中的详情web + 而且是发货宝项目里的
    isRefundDetailWeb() {
      let refundStatus = dotData(this.orderDetail, 'fhbOrder.refundStatus')
      if (refundStatus === 'refund|100' && (this.isFhbAdminPath < 0)) {
        return true
      } else {
        return false
      }
    }
  },
  methods: {
    // 服务承诺
    pledge() {
      this.BighomeServiceCommitment = this.fhbOrderBiddingLog.bighomeServiceCommitment
      let pledgeStr = `<p>1.` + this.BighomeServiceCommitment.carrSubject + `</p>
                         <p>&nbsp;&nbsp;&nbsp;` + this.BighomeServiceCommitment.freeForCarry + `</p>
                         <p>2.` + this.BighomeServiceCommitment.overmileSubject + `</p>
                         <p>&nbsp;&nbsp;&nbsp;` + this.BighomeServiceCommitment.coastForOvermile + `</p>
                         <p>3.` + this.BighomeServiceCommitment.storageSubject + `</p>
                         <p>&nbsp;&nbsp;&nbsp;` + this.BighomeServiceCommitment.freeForStorage + `</p>
                         <p>4.` + this.BighomeServiceCommitment.uniformSubject + `</p>
                         <p>&nbsp;&nbsp;&nbsp;` + this.BighomeServiceCommitment.serviceOnUniform + `</p>
                         <p>5.` + this.BighomeServiceCommitment.basicSubject + `</p>
                         <p>&nbsp;&nbsp;&nbsp;` + this.BighomeServiceCommitment.basicCommitment + `</p>`
      this.$alert(pledgeStr, '师傅服务承诺', {
        showConfirmButton: '关闭',
        dangerouslyUseHTMLString: true
      })
    },
    // 费用详情
    feesDetail() {
      this.$refs.modalFeesDetail.show()
    }
  }
}
</script>

<style scoped>

</style>
